﻿using AntUnion.FrameWork.Model.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AntUnion.FrameWork.Web.Controllers
{
    public class SystemMaintenanceController : Controller
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            using (mtContext mtContext = new mtContext())
            {
                // 从数据库获取要跳转的页面
                TbSystemConfig systemMaintenanceConfig = mtContext.TbSystemConfigs.Where(k => k.Language == "Public" && k.MenuName == "systemMaintenance" && k.Status == true && k.ConfigTab == 1).FirstOrDefault();
                // 根据数据库值跳转到指定页面
                if (systemMaintenanceConfig != null && systemMaintenanceConfig.Value == "1")
                {
                    filterContext.Result = new RedirectResult("~/Error/SystemMaintenance");
                    return;
                }
            }
            base.OnActionExecuting(filterContext);
        }
    }
}
